// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
    speed:number=0.1
    direction:cc.Vec2=null
  刹车:cc.Node=null
  油门:cc.Node=null
  onLoad(){
    this.油门=cc.find("Canvas/油门")    
    this.油门.on("touchstart",this.踩油门,this)
    this.油门.on("touchend",this.松油门,this)
  }
  踩油门(){
    if(cc.find("Canvas/游戏摇杆底盘/手柄_dark").getPosition().x===0&&cc.find("Canvas/游戏摇杆底盘/手柄_dark").getPosition().y===0){
      
      return
    }
    
    cc.find("Canvas/游戏摇杆底盘/手柄_dark").getComponent("mover").持续加速()
    cc.find("Canvas/游戏摇杆底盘/手柄_dark").getComponent("mover").最大速度=10
  }
  松油门(){
    if(cc.find("Canvas/游戏摇杆底盘/手柄_dark").getPosition().x===0&&cc.find("Canvas/游戏摇杆底盘/手柄_dark").getPosition().y===0){
      this.speed=0
      return
    }
    cc.find("Canvas/游戏摇杆底盘/手柄_dark").getComponent("mover").持续加速()
    cc.find("Canvas/游戏摇杆底盘/手柄_dark").getComponent("mover").最大速度=2
  }
    start () {

    }
    update (dt) {
       
        if(this.direction===null) return
            let dx=this.speed*this.direction.x;
            let dy=this.speed*this.direction.y;
            let pos=this.node.getPosition()
            pos.x+=dx
            pos.y+=dy
            this.node.setPosition(pos)
    }

}
